package com.slwish.xty.adapter;


import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.slwish.xty.R;
import com.slwish.xty.entity.CreditTourismInfoModel;
import com.slwish.xty.entity.ServiceList;

import java.util.List;

/**
 * 模块说明：首页适配器
 *
 * @author 陈浩
 * @date 2017/11/28
 */
public class MainAdapter extends BaseQuickAdapter<CreditTourismInfoModel, BaseViewHolder> {

    public MainAdapter(@Nullable List<CreditTourismInfoModel> data) {
        super(R.layout.item_main, data);
//        inflater = LayoutInflater.from(mContext);
    }

    @Override
    protected void convert(BaseViewHolder helper, CreditTourismInfoModel item) {
        int position = helper.getAdapterPosition();
        helper.setText(R.id.tv_num, item.getViewCount() + "次").setText(R.id.tv_name, item.getScenicName())
                .setText(R.id.tv_distance, item.getDistance() + "km")
                .setText(R.id.tv_point, item.getPoint() + "分");
        helper.setGone(R.id.iv_is_sincerity, !item.getSincerityMerchant().equals("0"));
        helper.setGone(R.id.rl_rm, position - 2 == 0);
        List<ServiceList> serviceItem = item.getServiceItem();
        LinearLayout rl = helper.getView(R.id.ll_service_item);
//        RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
//        params.leftMargin = 19;
//        rl.setLayoutParams(params);
        String imageUrl = item.getLogo().get(0);
        RequestOptions options = new RequestOptions();
        options.placeholder(R.mipmap.zhanweifu_home)
                .error(R.mipmap.zhanweifu_home)
                .skipMemoryCache(true);
        Glide.with(mContext).load(imageUrl).apply(options).into((ImageView) helper.getView(R.id.iv_head));
        for (ServiceList serviceItemBean : serviceItem) {
            String serviceName = serviceItemBean.getServiceName();
            View view = mLayoutInflater.inflate(R.layout.item_main_service_content, null);
            TextView tvItem = view.findViewById(R.id.tv_item);
            tvItem.setText(serviceName);
            rl.addView(view);
        }
    }
}
